﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OracleClient;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

        DataConnection.str = @"Data Source=xe;User ID=ODER;Password=12345";
        if (Session["GioHang"] == null)
            TaoGioHang();

        XuatThongTinGioHang();
        lbllabel.Text = LoadSlide();

    }

    private string LoadSlide()
    {

        // get new Sach
        DataTable dt = DataConnection.GetDatatableByStoreProcedureNameNoParam("NGOCTRAN.sp_getSachMoi");
        string strHTML = "<div id='mcts1'>";


        for (int i = 0; i < dt.Rows.Count; i++)
        {
            strHTML += @"<a href='chitietsanpham.aspx?MaSach=" + dt.Rows[i]["MaSach"] + @"'><img src='image/" + dt.Rows[i]["HINH"] + @"' /></a>";


        }
        strHTML += "</div>";

        return strHTML;
    }



    
    private void TaoGioHang()
    {
        DataTable gioHang = new DataTable();
        gioHang.Columns.Add("masach", typeof(string));
        gioHang.Columns.Add("hinh", typeof(string));
        gioHang.Columns.Add("tensach", typeof(string));
        gioHang.Columns.Add("dongia", typeof(int));
        gioHang.Columns.Add("soluong", typeof(int));

        Session["GioHang"] = gioHang;
    }
    private void XuatThongTinGioHang()
    {
        DataTable dt = (DataTable)Session["GioHang"];
        int soSP = 0;
        int soTien = 0;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            soTien = soTien + int.Parse(dt.Rows[i]["dongia"].ToString()) * int.Parse(dt.Rows[i]["soluong"].ToString());
            soSP = soSP + int.Parse(dt.Rows[i]["soluong"].ToString());
        }
        lbquyen.Text = "" + soSP;
        lbtongtien.Text = "" + soTien;
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Response.Redirect("TrangTheLoai.aspx?noidung=");   
    }
   
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        
    }

    protected void Button1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("KetQua.aspx?noidung=" + txttim.Text + "&loai=" + ddltim.SelectedIndex);

    }
}

